#include "logs/hsllog.hpp"
using namespace std;
using namespace hsl_log;

void test_1()
{

    // LogMsg msg(LogLevel::value::INFO, 13, "test.cc", "Root", "一切正常");

    // Formatter fmt("日志：[%d][%n");

    // string str = fmt.format(msg);

    // cout<<str<<endl;

    // cout<<hsl_log::LogLevel::toString(hsl_log::LogLevel::value::UNKNOW)<<endl;
    //  cout<<hsl_log::util::date::now()<<endl;
    //  hsl_log::util::file::create_directory_1(hsl_log::util::file::path("./abc/bcd/a.txt"));
    // cout<<hsl_log::util::file::path("test.cc")<<endl;

    // hsllog::util::File::CreateDirectory_1("22");
}

void test_2()
{
    // LogMsg msg(LogLevel::value::INFO, 13, "test.cc", "Root", "一切正常");

    // Formatter fmt("日志：[%d][%n");

    // string str = fmt.format(msg);

    // LogSink::ptr out_lsp = SinkFactory::create<StdoutSink>();
    // LogSink::ptr file_lsp = SinkFactory::create<FileSink>("./logfile/test.log");
    // LogSink::ptr roll_lsp = SinkFactory::create<RollSink>("./logfile/roll-", 1024 * 1024);

    // size_t cur=0;
    // size_t count =0;
    // while(cur<1024*1024*10)
    // {
    //     string  tmp = str+to_string(count++);
    //     roll_lsp->log(tmp.c_str(),tmp.size());
    //     cur+=tmp.size();
    // }

    // out_lsp->log(str.c_str(),str.size());
    // file_lsp->log(str.c_str(),str.size());
    // roll_lsp->log(str.c_str(),str.size());
}

// void test_3()
// {
//     string name = "sync_logger";
//     LogLevel::value level_limit = LogLevel::value::WARN;
//     Formatter::ptr fmt(new Formatter("[%d{%H:%M:%S}][%t][%p][%c][%f:%l]%T%m%n"));

//     LogSink::ptr out_lsp = SinkFactory::create<StdoutSink>();
//     LogSink::ptr file_lsp = SinkFactory::create<FileSink>("./logfile/test.log");
//     LogSink::ptr roll_lsp = SinkFactory::create<RollSink>("./logfile/roll-", 1024 * 1024);

//     vector<LogSink::ptr> sinks = {out_lsp,file_lsp,roll_lsp};

//     Logger::ptr logger(new SyncLogger(name,fmt,sinks,level_limit));


//     logger->debug(__FILE__,__LINE__,"%s","测试日志");
//     logger->error(__FILE__,__LINE__,"%s","测试日志");
//     logger->info(__FILE__,__LINE__,"%s","测试日志");
//     logger->warn(__FILE__,__LINE__,"%s","测试日志");
//     logger->fatal(__FILE__,__LINE__,"%s","测试日志");

//     size_t cur=0;
//     size_t count =0;
//     while(cur<1024*1024*10)
//     {
//         logger->fatal(__FILE__,__LINE__,"%s-%d","测试日志",count++);
//         cur+=20;
//     }

// }



void test_4()
{


    unique_ptr<hsl_log::Logger::Builder> builder(new hsl_log::GlobalLoggerBuilder());
    builder->buildFormatter("%m%n");
    builder->buildLoggerLevel(hsl_log::LogLevel::value::WARN);

    builder->buildLoggerName("sync_logger");
    builder->buildLoggerType(Logger::Type::LOGGER_SYNC);
    builder->buildSink<hsl_log::FileSink>("./logfile/yesy.log");
    builder->buildSink<hsl_log::StdoutSink>();
    Logger::ptr logger = builder->build(); 



    logger->debug("%s","测试日志");
    logger->error("%s","测试日志");
    logger->info("%s","测试日志");
    logger->warn("%s","测试日志");
    logger->fatal("%s","测试日志");

    size_t cur=0;
    size_t count =0;
    while(cur<1024*1024*10)
    {
        logger->fatal("%s-%d","测试日志",count++);
        cur+=20;
    }

}


void test_5()
{
    unique_ptr<hsl_log::Logger::Builder> builder(new hsl_log::GlobalLoggerBuilder());
    builder->buildFormatter("[%d][%c]%m%n");
    builder->buildLoggerLevel(hsl_log::LogLevel::value::WARN);

    builder->buildLoggerName("async_logger");
    builder->buildLoggerType(Logger::Type::LOGGER_ASYNC);
    builder->buildEnableUnSafeAsync();
    builder->buildSink<hsl_log::FileSink>("./logfile/async.log");
    builder->buildSink<hsl_log::StdoutSink>();
    Logger::ptr logger = builder->build(); 



    logger->debug(__FILE__,__LINE__,"%s","测试日志");
    logger->error(__FILE__,__LINE__,"%s","测试日志");
    logger->info(__FILE__,__LINE__,"%s","测试日志");
    logger->warn(__FILE__,__LINE__,"%s","测试日志");
    logger->fatal(__FILE__,__LINE__,"%s","测试日志");

    size_t count =0;
    while(count<500000)
    {
        logger->fatal(__FILE__,__LINE__,"%s-%d","测试日志",count++);
    }   
   
}

void test_6()
{

    //  unique_ptr<hsl_log::Logger::Builder> builder(new hsl_log::GlobalLoggerBuilder());
    // builder->buildFormatter("[%d][%c]%m%n");
    // builder->buildLoggerLevel(hsl_log::LogLevel::value::WARN);

    // builder->buildLoggerName("async_logger");
    // builder->buildLoggerType(Logger::Type::LOGGER_ASYNC);
    // builder->buildEnableUnSafeAsync();
    // builder->buildSink<hsl_log::FileSink>("./logfile/async.log");
    // builder->buildSink<hsl_log::StdoutSink>();
    // builder->build(); 

    //hsl_log::Logger::ptr logger = hsl_log::loggerManager::getInstance().getLogger("async_logger");

    LOGD("%s","测试日志");
    LOGE("%s","测试日志");
    LOGF("%s","测试日志");
    LOGI("%s","测试日志");
    LOGW("%s","测试日志");

    size_t count =0;
    while(count<500000)
    {
        LOGF("%s-%d","测试日志",count++);
    }   
   
}

int main()
{
    test_6();
    return 0;
}